
/**
* @Title: PriorityTest.java
* @Package com.leetone
* @Description: 【】
* @date 2018年3月7日 下午12:27:46
* @version V1.0
* @Company: 上海
* @author:[谭磊][leetone123@163.com]
*/

package com.leetone.simple;


/**
* @ClassName: PriorityTest
* @Description: 【线程优先级测试】
* @date 2018年3月7日 下午12:27:46
* @Company: 上海
* @author:[谭磊][leetone123@163.com]
*/

public class PriorityTest {
	public static class HighPriorityT extends Thread{
		static int count = 0;
		@Override
		public void run() {
			while(true)
			{
				synchronized(PriorityTest.class) {
					count++;
					if(count>10000000)
					{
						System.out.println("HighPriority is complete!");
						break;
					}
				}
			}
		};
	}
	
	public static class LowPriorityT extends Thread{
		static int count = 0;
		@Override
		public void run() {
			while(true)
			{
				synchronized(PriorityTest.class)
				{
					count++;
					if(count>10000000)
					{
						System.out.println("LowPriority is complete!");
						break;
					}
				}
			}
		}
	}
	/**
	* @Title: main
	* @Description: 【】
	* @date 2018年3月7日 下午12:27:46
	* @author:[谭磊][leetone123@163.com]
	* @param @param args    参数
	* @return void    返回类型
	* @throws
	*/

	public static void main(String[] args) {
		//设置了优先级后high被执行的次数明显会多，但是不保证每次都是high先完成
		Thread high = new HighPriorityT();
		Thread low = new LowPriorityT();
		high.setPriority(Thread.MAX_PRIORITY);
		low.setPriority(Thread.MIN_PRIORITY);
		low.start();
		high.start();
	}

}
